package study;

public class algorithm2 {
    public static void main(String[] args){
        int[] arr11 = {2 , 4 , 1 , 2 , 5 , 6 };
        int[] arr22 = {3 , 1 , 3 , 5 , 6 , 4 };
        int[] arr1 = new int[1000];
        int[] arr2 = new int[1000];
        for(int i = 0;i < 6;i++){
            arr1[i] = arr11[i];
            arr2[i] = arr22[i];
        }
        culculate(arr1,arr2);
    }
    public static void culculate(int[] arr1,int[] arr2){
        int head1 = 0;
        int back1 = arr1.length - 1;
        int head2 = 0;
        int back2 = arr2.length - 1;
        int i = 0,j = 0, u =0;
        int[] arr = new int[1000];
        while(head1 < back1 || head2 < back2){
            for(int y = 0;y < i;y++){
                if(arr1[head1] == arr[y]){
                    while(y < i){
                        arr1[back1++] = arr[y++];
                    }
                    arr1[back1++] = arr1[head1];
                }
            }
            arr[i] = arr1[head1];
            i++;
            for(int y = 0;y < i;y++){
                if(arr2[head2] == arr[y]){
                    while(y < i){
                        arr2[back2++] = arr[y++];
                    }
                    arr2[back2++] = arr2[head2];
                }else if(y == i - 1 && arr1[head1] != arr[y]){
                    arr[i] = arr1[head1++];
                }
            }
            i++;
        }
        System.out.println(arr1[head1]);
        System.out.println(arr2[head2]);
    }
}
